package com.winit.openapi.ums.controller;

import java.util.HashMap;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.winit.common.spi.context.CommandContext;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;
import com.winit.ums.spi.distributor.DistributorService;
import com.winit.ums.spi.distributor.command.RegisterDistributorCommand;

@Controller
@RequestMapping(value = "/ums/distributor")
public class DistributorController extends BaseController {

    @Resource
    private DistributorService distributorService;

    /**
     * 分销商注册接口
     * 
     * @param requestMsg
     * @param responseMsg
     * @return String
     */
    @RequestMapping(value = "/registerDistributor")
    public String registerDistributor(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {

        // 客户注册
        RegisterDistributorCommand command = JSON.parseObject(requestMsg.getData().toString(),
            RegisterDistributorCommand.class);
        command.setCtx(CommandContext.getContext());
        String token = distributorService.registerDistributor(command);
        Map<String, String> data = new HashMap<String, String>();
        data.put("token", token);
        responseMsg.setData(data);
        return SUCCESS;
    }
}
